package com.wingsboat.graphvis.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.wingsboat.graphvis.domain.GvNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wingsboat.common.log.annotation.Log;
import com.wingsboat.common.log.enums.BusinessType;
import com.wingsboat.common.security.annotation.RequiresPermissions;
import com.wingsboat.graphvis.domain.GvNodeLink;
import com.wingsboat.graphvis.service.IGvNodeLinkService;
import com.wingsboat.common.core.web.controller.BaseController;
import com.wingsboat.common.core.web.domain.AjaxResult;
import com.wingsboat.common.core.utils.poi.ExcelUtil;
import com.wingsboat.common.core.web.page.TableDataInfo;

/**
 * 节点连接Controller
 * 
 * @author wangzhong
 * @date 2024-04-20
 */
@RestController
@RequestMapping("/link")
public class GvNodeLinkController extends BaseController
{
    @Autowired
    private IGvNodeLinkService gvNodeLinkService;

    /**
     * 查询节点连接列表
     */
    @RequiresPermissions("graphvis:link:list")
    @GetMapping("/list")
    public TableDataInfo list(GvNodeLink gvNodeLink)
    {
        startPage();
        List<GvNodeLink> list = gvNodeLinkService.selectGvNodeLinkList(gvNodeLink);
        return getDataTable(list);
    }

    /**
     * 查询节点信息列表
     */
    @RequiresPermissions("graphvis:node:list")
    @GetMapping("/listAll")
    public AjaxResult listAll(GvNodeLink gvNodeLink)
    {
        List<GvNodeLink> list = gvNodeLinkService.selectGvNodeLinkList(gvNodeLink);
        return AjaxResult.success(list);
    }

    /**
     * 导出节点连接列表
     */
    @RequiresPermissions("graphvis:link:export")
    @Log(title = "节点连接", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GvNodeLink gvNodeLink)
    {
        List<GvNodeLink> list = gvNodeLinkService.selectGvNodeLinkList(gvNodeLink);
        ExcelUtil<GvNodeLink> util = new ExcelUtil<GvNodeLink>(GvNodeLink.class);
        util.exportExcel(response, list, "节点连接数据");
    }

    /**
     * 获取节点连接详细信息
     */
    @RequiresPermissions("graphvis:link:query")
    @GetMapping(value = "/{linkId}")
    public AjaxResult getInfo(@PathVariable("linkId") Long linkId)
    {
        return success(gvNodeLinkService.selectGvNodeLinkByLinkId(linkId));
    }

    /**
     * 新增节点连接
     */
    @RequiresPermissions("graphvis:link:add")
    @Log(title = "节点连接", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GvNodeLink gvNodeLink)
    {
        return toAjax(gvNodeLinkService.insertGvNodeLink(gvNodeLink));
    }

    /**
     * 修改节点连接
     */
    @RequiresPermissions("graphvis:link:edit")
    @Log(title = "节点连接", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GvNodeLink gvNodeLink)
    {
        return toAjax(gvNodeLinkService.updateGvNodeLink(gvNodeLink));
    }

    /**
     * 删除节点连接
     */
    @RequiresPermissions("graphvis:link:remove")
    @Log(title = "节点连接", businessType = BusinessType.DELETE)
	@DeleteMapping("/{linkIds}")
    public AjaxResult remove(@PathVariable Long[] linkIds)
    {
        return toAjax(gvNodeLinkService.deleteGvNodeLinkByLinkIds(linkIds));
    }
}
